/*
 * Created by IntelliJ IDEA.
 * User: amrk
 * Date: 15/02/2005
 * Time: 21:25:57
 */
package com.talios.jira.browser;

import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.JDOMExternalizable;
import com.intellij.openapi.util.WriteExternalException;
import com.talios.jira.idea.JDomSupport;
import org.jdom.Element;

public class ColumnSetting implements JDOMExternalizable {
    private String id;
    private Integer position;
    private Integer width;

    public ColumnSetting() {
    }

    public ColumnSetting(String id, Integer position, Integer width) {
        this.id = id;
        this.position = position;
        this.width = width;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public Integer getPosition() {
        return position;
    }

    public void setPosition(Integer position) {
        this.position = position;
    }

    public Integer getWidth() {
        return width;
    }

    public void setWidth(Integer width) {
        this.width = width;
    }


    public void readExternal(Element element) throws InvalidDataException {
        setId(JDomSupport.getAttributeWithDefault(element, "id", ""));
        setPosition(new Integer(JDomSupport.getAttributeWithDefault(element, "position", "0")));
        setWidth(new Integer(JDomSupport.getAttributeWithDefault(element, "width", "-1")));
    }

    public void writeExternal(Element element) throws WriteExternalException {
        if (getId() != null) {
            element.setAttribute("id", getId());
        }
        if (getPosition() != null) {
            element.setAttribute("position", getPosition().toString());
        }
        if (getWidth() != null) {
            element.setAttribute("width", getWidth().toString());
        }
    }
}